package com.ymatou.iapi.godmch.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.bindmchBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.getAllSubMchIdListBean;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymatou.iapi.godmch.service.getAllSubMchIdListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
/**
*获取所有下级商户id列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getAllSubMchIdList{
	private static getAllSubMchIdListBean bean;
	private static getAllSubMchIdListCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取所有下级商户id列表");
	}

	@Before
	public void caseUp() {
		bean=new getAllSubMchIdListBean();
		call=new getAllSubMchIdListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAllSubMchIdList_001() {
		Logger.start(true,"正例-商户是渠道商,没有下级代理");
		try {
			
			UserCreateBean usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean);
			usercreateBean=DGUserCallService.initUsercreateBean();
			//渠道
			createmchBean createBean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createBean);
			
			bean.setMchId(userId_channl);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        Logger.verifyEquals("{}", call.getResult(), "验证返回成功result为空");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAllSubMchIdList_002() {
		Logger.start(true,"正例-商户是渠道商,有下一级代理");
		try {
			
			UserCreateBean usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean);
			usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_agent=DGUserCallService.UserCreateCall(usercreateBean);
			//渠道
			createmchBean createBean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createBean);
			//代理
			List<createmchBean>  createmchList=GodmchManageCallService.InitcreatemchBeanForAgent(userId_channl,userId_agent);
			GodmchManageCallService.createmchCallForAgent(createmchList.toArray(new
					createmchBean[0]));
			
			bean.setMchId(userId_channl);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        Logger.verifyEquals(userId_agent, call.getSubMchIdList().get(0), "验证返回成功subMchIdList");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAllSubMchIdList_003() {
		Logger.start(true,"正例-商户是渠道商,有下两级代理");
		try {
			UserCreateBean usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean);
			usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_agent1=DGUserCallService.UserCreateCall(usercreateBean);
			usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_agent2=DGUserCallService.UserCreateCall(usercreateBean);
			//渠道
			createmchBean createBean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createBean);
			//代理
			List<createmchBean>  createmchList=GodmchManageCallService.InitcreatemchBeanForAgent(userId_channl,userId_agent1);
			GodmchManageCallService.createmchCallForAgent(createmchList.toArray(new
					createmchBean[0]));
			List<createmchBean>  createmchList2=GodmchManageCallService.InitcreatemchBeanForAgent(userId_channl,userId_agent2);
			GodmchManageCallService.createmchCallForAgent(createmchList2.toArray(new
					createmchBean[0]));
			
			bean.setMchId(userId_channl);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        Logger.verifyEquals(userId_agent1, call.getSubMchIdList().get(0), "验证返回subMchIdList第一个代理商");		
	        Logger.verifyEquals(userId_agent2, call.getSubMchIdList().get(1), "验证返回subMchIdList第二个代理商");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAllSubMchIdList_004() {
		Logger.start(true,"正例-商户是普通代理,没有下级代理");
		try {
			UserCreateBean usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean);
			usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_agent=DGUserCallService.UserCreateCall(usercreateBean);
			//渠道
			createmchBean createBean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createBean);
			//代理
			List<createmchBean>  createmchList=GodmchManageCallService.InitcreatemchBeanForAgent(userId_channl,userId_agent);
			GodmchManageCallService.createmchCallForAgent(createmchList.toArray(new
					createmchBean[0]));
			
			bean.setMchId(userId_agent);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        Logger.verifyEquals("{}", call.getResult(), "验证返回成功result为空");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAllSubMchIdList_005() {
		Logger.start(true,"正例-商户是vip渠道商,没有下级代理");
		try {
			
			UserCreateBean usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean);
			usercreateBean=DGUserCallService.initUsercreateBean();
			//渠道
			createmchBean createBean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createBean);
			GodmchManageCallService.SetVip(userId_channl);
			
			bean.setMchId(userId_channl);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        Logger.verifyEquals("{}", call.getResult(), "验证返回成功result为空");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAllSubMchIdList_006() {
		Logger.start(true,"正例-商户是vip渠道商,有下一级代理");
		try {
			UserCreateBean usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean);
			usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_agent=DGUserCallService.UserCreateCall(usercreateBean);
			//渠道
			createmchBean createBean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createBean);
			GodmchManageCallService.SetVip(userId_channl);//设置vip
			
			//代理
			List<createmchBean>  createmchList=GodmchManageCallService.InitcreatemchBeanForAgent(userId_channl,userId_agent);
			GodmchManageCallService.createmchCallForAgent(createmchList.toArray(new
					createmchBean[0]));
			
			
			bean.setMchId(userId_channl);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        Logger.verifyEquals(userId_agent, call.getSubMchIdList().get(0), "验证返回成功subMchIdList");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAllSubMchIdList_007() {
		Logger.start(true,"正例-商户是vip渠道商,有下两级代理");
		try {
			UserCreateBean usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean);
			usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_agent1=DGUserCallService.UserCreateCall(usercreateBean);
			usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_agent2=DGUserCallService.UserCreateCall(usercreateBean);
			//渠道
			createmchBean createBean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createBean);
			GodmchManageCallService.SetVip(userId_channl);//设置vip
			
			//代理
			List<createmchBean>  createmchList=GodmchManageCallService.InitcreatemchBeanForAgent(userId_channl,userId_agent1);
			GodmchManageCallService.createmchCallForAgent(createmchList.toArray(new
					createmchBean[0]));
			List<createmchBean>  createmchList2=GodmchManageCallService.InitcreatemchBeanForAgent(userId_channl,userId_agent2);
			GodmchManageCallService.createmchCallForAgent(createmchList2.toArray(new
					createmchBean[0]));
			
			bean.setMchId(userId_channl);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        Logger.verifyEquals(userId_agent1, call.getSubMchIdList().get(0), "验证返回成功subMchIdList");
	        Logger.verifyEquals(userId_agent2, call.getSubMchIdList().get(1), "验证返回成功subMchIdList");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAllSubMchIdList_008() {
		Logger.start(true,"正例-商户是Vip代理,有下级代理");
		try {
			UserCreateBean usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean);
			usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_agent1=DGUserCallService.UserCreateCall(usercreateBean);
			usercreateBean=DGUserCallService.initUsercreateBean();
			int userId_agent2=DGUserCallService.UserCreateCall(usercreateBean);
			//渠道
			createmchBean createBean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createBean);
			GodmchManageCallService.SetVip(userId_channl);//设置vip
			
			//代理
//			List<createmchBean>  createmchList=GodmchManageCallService.InitcreatemchBeanForAgent(userId_channl,userId_agent1);
//			GodmchManageCallService.createmchCallForAgent(createmchList.toArray(new
//					createmchBean[0]));
//			
//			List<createmchBean>  createmchList2=GodmchManageCallService.InitcreatemchBeanForAgent(userId_channl,userId_agent2);
//			GodmchManageCallService.createmchCallForAgent(createmchList2.toArray(new
//					createmchBean[0]));
			
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForAgent2(userId_channl, userId_agent1);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			createmchBean createmchbean2=GodmchManageCallService.InitcreatemchBeanForAgent2(userId_channl, userId_agent2);
			GodmchManageCallService.createmchCallForChannel(createmchbean2);
			//渠道 邀请码
			CreateCodeBean createbean=GodmchManageCallService.InitcreateCodeBeanForAgent(userId_channl);
			CreateCodeCall createcall=GodmchManageCallService.createCodeCall(createbean);
			//代理 邀请码
			CreateCodeBean createbean1=GodmchManageCallService.InitcreateCodeBeanForAgent(userId_agent1);
			CreateCodeCall createcall1=GodmchManageCallService.createCodeCall(createbean1);
			//绑定
			bindmchBean bindmchbean=GodmchManageCallService.InitbindmchBean(userId_agent1, createcall.getCode());
			GodmchManageCallService.bindmchcall(bindmchbean);
			
			bindmchBean bindmchbean1=GodmchManageCallService.InitbindmchBean(userId_agent2, createcall1.getCode());
			GodmchManageCallService.bindmchcall(bindmchbean1);
			
			Logger.comment("userId_channl:"+userId_channl);
			Logger.comment("userId_agent1:"+userId_agent1);
			Logger.comment("userId_agent2:"+userId_agent2);
			
			bean.setMchId(userId_agent1);
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        Logger.verifyEquals(userId_agent2, call.getSubMchIdList().get(0), "验证返回成功subMchIdList");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAllSubMchIdList_009() {
		Logger.start(true,"反例-mchId为空-返沪失败");
		try {
			//bean.setMchId();
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证返回成功status值");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}